<?php
namespace app\api\controller;
use app\common\model\User as UserModel;

use app\api\controller\Weixin;

use think\Controller;
use think\Config;
use think\Db;
use think\Session;
use think\Cookie;

/**
 * 推送提醒
 * Class Notice
 * @package app\api\controller
 */
class Notice extends Controller
{
    protected $user_model;

    protected function _initialize()
    {
//        parent::_initialize();
//        $this->user_model        = new UserModel();

    }

    /**
     * 微信推送
     */
    public function weixin_push($uid,$status,$project,$time,$feedback)
    {
        $user  = $this->user_model->find($uid);
        if($user['openid']){
            $Weixin=new Weixin();
            $get_user=$Weixin->get_user($user['openid']);
            if($get_user['subscribe']==1){
                $messages_data=[];
                $messages_data['touser']=$user['openid'];
                if($status==1){
                    $messages_data['template_id']="ukuTG12YdE3dJhetAoJuIu6elCa7nuP2cF-QEJswlQo";
                }
                if($status==2){
                    $messages_data['template_id']="MP-A5UC6HSDi76QRrZ1Mteu3Ih66LbBLe-oT7uB0UUc";
                }
                $messages_data['url']='http://yuyue.chinahymuseum.com'.url('wap/order/index');
                $type_status[1]='预约成功';
                $type_status[2]='预约不通过';
                $messages['first']=array("value"=>"".$type_status[$status]."","color"=>"#173177");
                $messages['keyword1']=array("value"=>$project,"color"=>"#173177");
                $messages['keyword2']=array("value"=>date('Y年m月d日',strtotime($time)),"color"=>"#173177");
                $messages['keyword3']=array("value"=>$feedback,"color"=>"#173177");
                $messages['remark']=array("value"=>'查看详情',"color"=>"#173177");
                $messages_data['data']=$messages;
                $Weixin->send_template_messages($messages_data);
            }
        }
    }

}